package com.sessionFactory.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SessionFactorys {
	public static SqlSession getSqlSessions(){
		InputStream in = null;
		SqlSession se = null;
		//第一步：通过org.apache.ibatis.io.Resources getResourceAsStream（）获取配置文件
		 try {
			in = Resources.getResourceAsStream("SqlMapConfig.xml");
			//第二步：sqlSessionFactory 通过new SqlSessionFactoryBuilder().build(in); 
			//构建工sqlSessionFactory 对象
			SqlSessionFactory build = new SqlSessionFactoryBuilder().build(in);
			//第三步：打开一个sqlsession 帮助我们执行sql 语句（此处的sql 指的 配置文件中的sql）
			se = build.openSession();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return se;
	}
}
